package com.seari.custody.service.Impl;

import com.alibaba.fastjson.JSONObject;
import com.seari.custody.bean.*;
import com.seari.custody.component.MinIoUtil;
import com.seari.custody.mapper.ReportProjectMapper;
import com.seari.custody.mapper.SpecialProtectionMapper;
import com.seari.custody.mapper.TechnicalAdviceMapper;
import com.seari.custody.mapper.TechnicalAuditOpinionMapper;
import com.seari.custody.pojo.RecordsSystsemResponse;
import com.seari.custody.pojo.RecordsSystsemResquest;
import com.seari.custody.service.TechnicalAuditOpinionService;
import com.seari.custody.util.Common;
import com.seari.custody.util.HttpClientUtil;
import com.seari.custody.util.UUIDUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.*;

@Service("TechnicalAuditOpinionService")
@Transactional(rollbackFor = Exception.class)
public class TechnicalAuditOpinionServiceImpl implements TechnicalAuditOpinionService {

    @Value("${record.url}")
    private String recordUrl;//档案系统下载接口地址

    @Value("${minio.projectpdf.bucket}")
    private String minioProjectPdf;//minio project pdf桶地址

    @Value("${minio.projectword.bucket}")
    private String minioProjectWord;//minio project word桶地址

    @Value("${minio.word}")
    private String minioword;

    @Value("${minio.fileAddress}")
    private String fileAddress;

    @Autowired
    private TechnicalAdviceMapper technicalAdviceMapper;

    @Autowired
    private TechnicalAuditOpinionMapper technicalAuditOpinionMapper;

    @Autowired
    private SpecialProtectionMapper specialProtectionMapper;

    @Autowired
    private SpecialProtectionServiceImpl specialProtectionServiceImpl;

    @Autowired
    private MinIoUtil minIoUtil;

    @Autowired
    private ReportProjectMapper reportProjectMapper;

    @Override
    public Map<String, String> passTechnical(TechnicalAuditOpinion technicalAuditOpinion) throws Exception {
        Map<String, String> passmap = new HashMap<>();
        //档案系统文件id
        String fileId = technicalAuditOpinion.getFileId();
        //文件名称
        String FileName = technicalAuditOpinion.getFileName();
        // 获取文件前缀名
        String caselsh = Common.specialCharacter(FileName.substring(0, FileName.lastIndexOf(".pdf")));
        SimpleDateFormat impleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");//设置日期格式
        long time = Long.parseLong(impleDateFormat.format(new Date()));
        String FileNamPDF = caselsh + time + ".pdf";
        //技审人员工号
        String personNumber = technicalAuditOpinion.getPersonNumber();
        //项目的no值
        String no = technicalAuditOpinion.getNo();
        //1、获取档案系统id下载到minio本地文件服务器上
        downRecodeFile(fileId, FileNamPDF, personNumber);
        //2、根据uuid读取工程详细信息

        Map<String, String> map = new HashMap();
        map.put("no", no);
        Map<String, Object> map1 = technicalAdviceMapper.engineeringInformation(map);
        if (map1 == null || map1.isEmpty()) {
            passmap.put("code", "500");
            passmap.put("message", "技审无此项目");
            return passmap;
        }
        // 项目uuid
        String projectUuid = map1.get("uuid").toString();
        // 项目状态
        String flow_status = map1.get("flow_status").toString();

        // 根据UUID查询当前下发次数
        Map<String, Object> stringIntegerMap = reportProjectMapper.saverFileNumber(projectUuid);
        // 监护大纲下次次数
        Integer outlineNumber = Integer.valueOf(stringIntegerMap.get("outline_number").toString());
        // 技审意见下发次数
        Integer flowNumber = Integer.valueOf(stringIntegerMap.get("flow_number").toString());
        // 3、把盖章通过的pdf文件存储到数据库中
        TechnicalFile technicalFile = new TechnicalFile();
        Date date = new Date();
        String fileI = UUIDUtils.getUUID();
        technicalFile.setId(fileI);
        technicalFile.setProjectUuid(projectUuid);
        technicalFile.setNo(no);
        technicalFile.setFileName(FileNamPDF);
        technicalFile.setExtName("pdf");
        technicalFile.setFileEmcId(fileId);
        technicalFile.setUrl("/projectpdf/" + FileNamPDF);
        technicalFile.setFileType(FileNamPDF);
        technicalFile.setCreateTime(date);
        technicalFile.setFinalVersionFile(1);
        technicalFile.setOutlineNumber(outlineNumber);
        technicalFile.setOutlineNumber(flowNumber);
        Integer integer = technicalAuditOpinionMapper.fileInsertTechnical(technicalFile);
        if (integer != 1) {
            passmap.put("code", "500");
            passmap.put("message", "技审入库错误");
            return passmap;
        }
        // 盖章审核通过之后状态更改  如审核失败状态不变更
        if ("1".equals(flow_status) || "2".equals(flow_status) || "3".equals(flow_status) || "5".equals(flow_status)) {
            passmap.put("code", "500");
            passmap.put("message", "待办状态有误");
            return passmap;
        }
        if ("4".equals(flow_status)) {
            technicalAdviceMapper.updateEngineeringLacerationStatus("6", projectUuid);
        }
        // 4、获取最新专项保护方案
        Map map4 = new HashMap();
        map4.put("uuid", projectUuid);
        map4.put("type", "0");
        Map<String, String> map2 = technicalAuditOpinionMapper.specialProtectionPlan(map4);
        String filename = map2.get("word_name");
        String fileSystemFile = map2.get("fileSystemFile");
        // 5.专项保护方案发送到档案系统
//        String wordName = minioword + filename;
//        String fileSystem = HttpClientUtil.uploadFilePdf(wordName, filename, "58");
        // 6.获取档案系统编号下发报审
        //项目类型
        String type = map1.get("type").toString();
        //项目所属人员工号
        String manager_number = map1.get("manager_number").toString();
        //2、回传数据到报审系统
        Map<String, String> report = new HashMap<>();
        report.put("no", no);
        report.put("fileId", fileSystemFile);
        report.put("fileName", filename);
        report.put("fileType", "pdf");
        report.put("type", type);
        report.put("personNumber", manager_number);
        report.put("UUID", fileI);
        System.out.println("report的值:" + report);
        Map<String, String> uploadedForReview = Common.uploadProjectFile(report);
        String code = uploadedForReview.get("code");
        String message = uploadedForReview.get("message");
        Boolean booleaned = code.equals("200");
        if (booleaned) {
            passmap.put("code", "200");
            passmap.put("message", message);
        } else {
            return uploadedForReview;
        }
        //日志-技审完结
        Integer flow_number = Integer.valueOf(stringIntegerMap.get("flow_number").toString());
        TechnicalHistory technicalHistory = new TechnicalHistory();
        technicalHistory.setCreateTime(new Date());
        technicalHistory.setOperationalType("1");
        technicalHistory.setOperationalFlow("6");
        technicalHistory.setOperationalContext("技审意见已完结");
        technicalHistory.setOperationalState("1");
        technicalHistory.setOperationalProject(projectUuid);
        technicalHistory.setOperationalNumber(flow_number);
        technicalAdviceMapper.serverTechnicalHistory(technicalHistory);
        // 7.下发成功状态变更
        passmap.put("code", "200");
        passmap.put("message", "查询成功");
        return passmap;
    }

    @Override
    public Integer fileInsertTechnical(TechnicalFile technicalFile) {
        return technicalAuditOpinionMapper.fileInsertTechnical(technicalFile);
    }

    @Override
    public Map<String, String> specialProtectionPlan(Map<String, String> map) {
        return technicalAuditOpinionMapper.specialProtectionPlan(map);
    }

    @Override
    public Map<String, String> sendTechnical(TechnicalAuditOpinion technicalAuditOpinion) throws Exception {
        Map<String, String> sendmap = new HashMap<>();
        //项目所属用户名
        String personNumber = technicalAuditOpinion.getPersonNumber();
        //项目编号
        String no = technicalAuditOpinion.getNo();
        //退回意见
        String opinion = technicalAuditOpinion.getOpinion();
        Map<String, String> map = new HashMap<>();
        map.put("no", no);
        Map<String, Object> stringObjectMap = technicalAdviceMapper.engineeringInformation(map);
        if (stringObjectMap == null || stringObjectMap.isEmpty()) {
            sendmap.put("code", "500");
            sendmap.put("message", "技审无此数据请重新推送再退回");
            return sendmap;
        }
        String uuid = stringObjectMap.get("uuid").toString();
        String flow_status = stringObjectMap.get("flow_status").toString();
        if ("1".equals(flow_status) || "2".equals(flow_status) || "3".equals(flow_status) || "5".equals(flow_status) || "6".equals(flow_status)) {
            sendmap.put("code", "500");
            sendmap.put("message", "待办状态有误");
            return sendmap;
        }
        Map<String, String> map1 = new HashMap<>();
        map1.put("uuid", uuid);
        Map<String, String> map2 = technicalAuditOpinionMapper.latestPermitsAndcomments(map1);
        if (map2 == null || map2.isEmpty()) {
            sendmap.put("code", "500");
            sendmap.put("message", "技审无此退回数据");
            return sendmap;
        }
        //获取技审的file_id
        Map<String, String> map3 = new HashMap<>();
        String file_id = map2.get("file_id");
        map3.put("return_opinion", opinion);
        map3.put("returned_state", "1");
        map3.put("file_id", file_id);
        map1.put("flow_status", "5");
        Integer integer = technicalAuditOpinionMapper.updateSendTechnical(map1);

        Integer integer1 = technicalAuditOpinionMapper.updateLatestPermits(map3);

        Map<String, Object> stringIntegerMap = reportProjectMapper.saverFileNumber(uuid);
        Integer flow_number = Integer.valueOf(stringIntegerMap.get("flow_number").toString());
        TechnicalHistory technicalHistory = new TechnicalHistory();
        technicalHistory.setCreateTime(new Date());
        technicalHistory.setOperationalType("1");
        technicalHistory.setOperationalFlow("5");
        technicalHistory.setOperationalContext("技审草稿被退回待处理");
        technicalHistory.setOperationalState("1");
        technicalHistory.setOperationalProject(uuid);
        technicalHistory.setOperationalNumber(flow_number);
        technicalAdviceMapper.serverTechnicalHistory(technicalHistory);

        if (integer == 1 && integer1 == 1) {
            sendmap.put("code", "200");
            sendmap.put("message", "退回成功");
        } else {
            sendmap.put("code", "500");
            sendmap.put("message", "退回失败，请重新修改数据");
        }
        return sendmap;
    }

    @Override
    public Integer updateSendTechnical(Map<String, String> map) {
        return null;
    }

    @Override
    public Map<String, String> latestPermitsAndcomments(Map<String, String> map) throws Exception {
        return technicalAuditOpinionMapper.latestPermitsAndcomments(map);
    }

    @Override
    public Integer updateLatestPermits(Map<String, String> map) throws Exception {
        return technicalAuditOpinionMapper.updateLatestPermits(map);
    }

    @Override
    public Map<String, String> updateTechnical(Map<String, String> map2) throws Exception {
        Map<String, String> sendmap = new HashMap<>();
        // MMS-项目编号
        String no = map2.get("no");
        // MMS-技审核工号
        String personNumber = map2.get("personNumber");
        // MMS-技审文件名
        String fileName = map2.get("fileName");
        System.out.println("fileName文件名：" + fileName);
        // MMS-档案系统id
        String fileId = map2.get("fileId");
        Map<String, String> map = new HashMap<>();
        map.put("no", no);
        Map<String, Object> stringObjectMap = technicalAdviceMapper.engineeringInformation(map);
        // 项目工程-技审工号
        String manager_number = stringObjectMap.get("manager_number").toString();
        //项目工程-技审状态
        String flow_status = stringObjectMap.get("flow_status").toString();
        // 项目工程-技审uuid
        String uuid = stringObjectMap.get("uuid").toString();
        if (stringObjectMap == null || stringObjectMap.isEmpty()) {
            sendmap.put("code", "500");
            sendmap.put("message", "技审无此工程信息");
            return sendmap;
        }
        // 判断技审的工号和传过来的工号是否相同
        if (!personNumber.equals(manager_number)) {
            sendmap.put("code", "500");
            sendmap.put("message", "办理人信息错误");
            return sendmap;
        }
        // 判断是否为专项保护方案处理中的状态
        if (!("6".equals(flow_status) || ("8".equals(flow_status)))) {
            sendmap.put("code", "500");
            sendmap.put("message", "待办状态有误");
            return sendmap;
        }

        // 流程状态更改
        Map<String, String> map1 = new HashMap<>();
        map1.put("flow_status", "7");
        map1.put("uuid", uuid);

        String[] as = fileId.split(",");
        String[] am = fileName.split(",");
        if (as.length != 2 || am.length != 2) {
            sendmap.put("code", "500");
            sendmap.put("message", "上传缺少pdf或word文件");
            return sendmap;
        }
        //档案系统文件id
        String asId1 = as[0];
        String asId2 = as[1];
        //文件名称
        String amId1 = am[0];
        String amId2 = am[1];

        //word获取文件后缀
        int begin = amId1.indexOf(".");
        int last = amId1.length();
        String aword = amId1.substring(begin, last);

        //PDF获取文件后缀
        int begin1 = amId2.indexOf(".");
        int last1 = amId2.length();
        String aPDF = amId2.substring(begin1, last1);
        //档案系统 word文档编号
        String recordId;
        //word文件地址
        String wordName;
        //pdf文件地址
        String pdfName;
        if (aword.equals(".docx")) {
            recordId = asId1;
            wordName = amId1;
            pdfName = amId2;
            downRecodeFileword(asId1, amId1, personNumber);
            downRecodeFilePdf(asId2, amId2, personNumber);
        } else {
            recordId = asId2;
            wordName = amId2;
            pdfName = amId1;
            downRecodeFileword(asId2, amId2, personNumber);
            downRecodeFilePdf(asId1, amId1, personNumber);
        }
        Date date = new Date();
        SpecialProtection specialProtection = new SpecialProtection();
        String fileI = UUIDUtils.getUUID();
        specialProtection.setNo(fileI);
        specialProtection.setFileUuid(uuid);
        specialProtection.setPdfName(pdfName);
        specialProtection.setFlowStatus("2");
        specialProtection.setWordName(wordName);
        specialProtection.setCreateTime(date);
        specialProtection.setType("1");
        specialProtection.setFileSystemFile(recordId);
        Integer integer = specialProtectionMapper.specialOverview(specialProtection);
        Integer projecttype = technicalAuditOpinionMapper.updateSendTechnical(map1);

        //监护大纲推送日志
        Map<String, Object> stringIntegerMap = reportProjectMapper.saverFileNumber(uuid);
        Integer flow_number = Integer.valueOf(stringIntegerMap.get("flow_number").toString());
        TechnicalHistory technicalHistory = new TechnicalHistory();
        technicalHistory.setCreateTime(new Date());
        technicalHistory.setOperationalType("1");
        technicalHistory.setOperationalFlow("7");
        technicalHistory.setOperationalContext("专项保护方案处理中");
        technicalHistory.setOperationalState("1");
        technicalHistory.setOperationalProject(uuid);
        technicalHistory.setOperationalNumber(flow_number);
        technicalAdviceMapper.serverTechnicalHistory(technicalHistory);


        if (integer == 1 && projecttype == 1) {
            sendmap.put("code", "200");
            sendmap.put("message", "");
            return sendmap;
        } else {
            sendmap.put("code", "500");
            sendmap.put("message", "数据异常，请重新添加");
            return sendmap;
        }
    }

    @Override
    public Map<String, String> sendBackSpecial(Map<String, String> map) throws Exception {
        String uuid = map.get("uuid");
        String project_feedback = map.get("feedback");
        Map<String, String> map1 = new HashMap<>();
        map1.put("project_feedback", project_feedback);
        map1.put("flow_status", "8");
        map1.put("uuid", uuid);
        technicalAuditOpinionMapper.updateSendTechnical(map1);
        Map<String, String> map2 = new HashMap<>();
        map2.put("code", "200");
        map2.put("message", "修改成功");
        return map2;
    }

    @Override
    public Map<String, Integer> orderVerdict(Map<String, String> map) {
        boolean isEmpty = map.containsKey("category");
        String managerNumber = map.get("manager_number");
        //征询类
        List<Integer> flowStatus1 = Arrays.asList(1, 3, 5);
        List<Integer> type1 = Arrays.asList(1, 2, 3, 4);
        Integer orderVerdict1 = technicalAuditOpinionMapper.orderVerdict(flowStatus1, type1, managerNumber);
        //许可类
        List<Integer> flowStatus2 = Arrays.asList(1, 3, 4, 5);
        List<Integer> type2 = Arrays.asList(5);
        Integer orderVerdict2 = technicalAuditOpinionMapper.orderVerdict(flowStatus2, type2, managerNumber);
        //专项保护方案
        List<Integer> flowStatus3 = Arrays.asList(7);
        List<Integer> type3 = Arrays.asList(5);
        Integer orderVerdict3 = technicalAuditOpinionMapper.orderVerdict(flowStatus3, type3, managerNumber);
        //监护大纲
        List<Integer> flowStatus4 = Arrays.asList(1, 3, 5, 6);
        List<Integer> type4 = Arrays.asList(5);
        Integer orderVerdict4 = technicalAuditOpinionMapper.MonitoringTheOutlineCount(flowStatus4, type4, managerNumber);
        int sum1 = orderVerdict1 + orderVerdict2 + orderVerdict3 + orderVerdict4;

        //已办
        //征询类
        List<Integer> haveflowStatus1 = Arrays.asList(2, 6);
        List<Integer> havetype1 = Arrays.asList(1, 2, 3, 4);
        Integer haveorderVerdict1 = technicalAuditOpinionMapper.orderVerdict(haveflowStatus1, havetype1, managerNumber);
        //许可类
        List<Integer> haveflowStatus2 = Arrays.asList(2, 6);
        List<Integer> havetype2 = Arrays.asList(5);
        Integer haveorderVerdict2 = technicalAuditOpinionMapper.orderVerdict(haveflowStatus2, havetype2, managerNumber);
        //专项保护方案
        List<Integer> haveflowStatus3 = Arrays.asList(8, 9);
        List<Integer> havetype3 = Arrays.asList(5);
        Integer haveorderVerdict3 = technicalAuditOpinionMapper.orderVerdict(haveflowStatus3, havetype3, managerNumber);
        //监护大纲
        List<Integer> haveflowStatus4 = Arrays.asList(2, 4, 7);
        List<Integer> havetype4 = Arrays.asList(5);
        Integer haveorderVerdict4 = technicalAuditOpinionMapper.MonitoringTheOutlineCount(haveflowStatus4, havetype4, managerNumber);
        int sum2 = haveorderVerdict1 + haveorderVerdict2 + haveorderVerdict3 + haveorderVerdict4;

        // 待办
        Map<String, Integer> map2 = new HashMap();
        if (isEmpty == true && map.get("category").equals("0")) {
            map2.put("reviewBacklogSum", sum1);
            map2.put("haveDoneSum", sum2);
            map2.put("reviewLicensing", orderVerdict2);
            map2.put("protectionPlan", orderVerdict3);
            map2.put("reviewConsult", orderVerdict1);
            map2.put("TheOutlineCount", orderVerdict4);
        } else {
            map2.put("reviewBacklogSum", sum1);
            map2.put("haveDoneSum", sum2);
            map2.put("reviewLicensing", haveorderVerdict2);
            map2.put("protectionPlan", haveorderVerdict3);
            map2.put("reviewConsult", haveorderVerdict1);
            map2.put("TheOutlineCount", haveorderVerdict4);
        }


        return map2;
    }

    @Override
    public Map<String, String> uploadstatus(TechnicalAuditOpinion technicalAuditOpinion) throws Exception {
        Map<String, String> passmap = new HashMap<>();
        // 工程编号获取对应的项目的uuid
        String reviewType;
        // 申报类型
        String type = technicalAuditOpinion.getType();
        // 档案系统编号
        String fileId = technicalAuditOpinion.getFileId();
        // 技审人员工号
        String personNumber = technicalAuditOpinion.getPersonNumber();
        // 技审文件名称
        String fileNameed = technicalAuditOpinion.getFileName();
        String fileName = new String(fileNameed.getBytes("UTF-8"));
        // 技审文件名称 去掉docx
        String abbreviationName = fileName.substring(0, fileName.indexOf("."));
        // 技审UUID
        String uuid = technicalAuditOpinion.getUuid();
        // 获取项目编号
        String no = technicalAuditOpinion.getNo();
        // 文件本地地址
        String document = fileAddress + fileName;
        if (type.equals("5")) {
            reviewType = "1";
        } else {
            reviewType = "2";
        }
        // 下载档案系统文件到本地地址
        nativeWord(fileId, fileName, personNumber, document);
        // 读取库中编号值
        Integer techniCalnum = technicalAdviceMapper.technicalnum(uuid);
        // 上传word文件更换num值
        int abc = 0;
        if (techniCalnum == null || techniCalnum == 0) {
            String amb = technicalAdviceMapper.numtextSum();
            Integer numtextSum = 0;
            if (amb == null) {
                numtextSum = 0;
            } else {
                numtextSum = Integer.parseInt(amb);
            }
            abc = numtextSum + 1;
        } else {
            //如编号值存在则
            abc = techniCalnum;
        }
        Map<String, Object> params = new HashMap<>();
        params.put("num", Common.zerofill(String.valueOf(abc)));
        Common common = new Common();
        // 生成有num的文件
        List<String> listed = common.downloadWord(document, params, abbreviationName);
        // 新生成带编号Word文件本地存储地址
        document = listed.get(0);
        // 新生成带编号Word文件本地存储用户名
        fileName = listed.get(1);
        // 本地文件上传到档案系统
        System.out.println("document:" + document);
        System.out.println("fileName:" + fileName);
        String fileSystem = HttpClientUtil.uploadLocalAddress(document, fileName, "58");
        System.out.println("档案系统编号：" + fileSystem);
        // 根据文件的档案系统编调用报审替换文件接口
        Map<String, String> map = new HashMap<>();
        map.put("fileId", fileSystem);
        map.put("no", no);
        map.put("fileName", fileName);
        map.put("type", type);
        map.put("personNumber", personNumber);
        Map<String, String> map1 = Common.replacetechnicalReview(map);
        String code = map1.get("code");
        String message = map1.get("message");
        Boolean booleaned = code.equals("200");
        // 判断是否数据满足要求
        if (booleaned) {
            passmap.put("code", "200");
            passmap.put("message", message);
        } else {
            return map1;
        }
        //生成专项保护方案的数据
        Map<String, String> map2 = new HashMap<>();
        String fileI = UUIDUtils.getUUID();
        map2.put("type", type);
        map2.put("uuid", uuid);
        map2.put("tnical", fileI);
        map2.put("name", abbreviationName);
        // 许可类生成专项保护方案
        if (reviewType.equals("1")) {
            // 生成专项保护方案
            String bb = specialProtectionServiceImpl.SpecialProtectionType(map2);
            if (bb.equals("上传技审文件成功")) {
                passmap.put("code", "200");
                passmap.put("message", bb);
            } else {
                passmap.put("code", "500");
                passmap.put("message", bb);
                return passmap;
            }
        }
        // 上传Word文件
        FileInputStream fileInputStream = new FileInputStream(new File(document));
        String contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
        // 上传word文档到minio目录
        minIoUtil.putObject("projectword", fileName, fileInputStream, contentType);
        // 根据word文件生成pdf文件
        List<String> listeded = common.makenpdf(document, abbreviationName);
        // 生成pdf文件地址
        String pdfread = listeded.get(0);
        // 生成pdf文件名称
        String pdfname = listeded.get(1);
        FileInputStream fileInputStream1 = new FileInputStream(new File(pdfread));
        String contentType1 = "application/pdf";
        minIoUtil.putObject("projectpdf", pdfname, fileInputStream1, contentType1);

        // 保存数据入库-技审表
        TechnicalAdvice ta = new TechnicalAdvice();
        Date date = new Date();
        // 最新的word文档的类型
        String techninum = technicalAdviceMapper.reviewopinion(uuid);
        ta.setFileUuid(uuid);
        ta.setFileName(fileName);
        ta.setPdfName(pdfname);
        ta.setFileId(fileI);
        ta.setUploadingId("1");
        ta.setCreateTime(date);
        ta.setUploadingType(techninum);
        ta.setFileSystemId(fileSystem);
        if (reviewType.equals("1")) {
            ta.setTechnicalReviewtype("1");
        } else {
            ta.setTechnicalReviewtype("2");
        }
        ta.setNumtext(String.valueOf(abc));
        technicalAdviceMapper.saverOverview(ta);
        //保存数据入库-更改流程
        technicalAdviceMapper.updateEngineeringLacerationStatus("4", uuid);
        return passmap;
    }

    @Override
    public Map<String, Object> selectStampPdf(Map<String, String> map) {
        Map<String, Object> map1 = new HashMap<>();
        Map<String, Object> map2 = new HashMap<>();

        String s = technicalAuditOpinionMapper.selectStampPdf(map);
        if (s == null || s.length() <= 0) {
            map1.put("code", "500");
            map1.put("message", "无此工程项目PDF文件");
            return map1;
        }
        map2.put("filePdf", s);
        map1.put("code", "200");
        map1.put("message", "查询成功");
        map1.put("data", map2);
        return map1;
    }


    //下载文件并上传到minio
    public synchronized void downRecodeFile(String fileEmcId, String fileName, String account) {
        try {
            //第一次请求获取 档案系统下载链接
            //档案系统文件ID
//            String fileEmcId = f.getFileEmcId();
            RecordsSystsemResquest recordsSystsemResquest = new RecordsSystsemResquest();
            recordsSystsemResquest.setFILE_ID(fileEmcId);
            //目前使用用户工号下载  同时使用一个用户下载会造成阻塞
            String reponseCon = HttpClientUtil.sendHttpPostJsonHasHeader(recordUrl, JSONObject.toJSONString(recordsSystsemResquest), account);
            //响应
            RecordsSystsemResponse recordsSystsemResponse = JSONObject.parseObject(reponseCon, RecordsSystsemResponse.class);
            String downUrl = recordsSystsemResponse.getRESPONSE();
            //第二次请求 获取文件到本地
            CloseableHttpClient client = HttpClients.createDefault();
            HttpGet httpget = new HttpGet(downUrl);
            CloseableHttpResponse response = client.execute(httpget);

            HttpEntity entity = response.getEntity();
            InputStream is = entity.getContent();
            String contentType = "application/pdf";
            //把文件放置Minio桶(pdf文件夹)
            minIoUtil.putObject(minioProjectPdf, fileName, is, contentType);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 下载word文件并上传到minio
     *
     * @param fileEmcId
     * @param fileName
     * @param account
     */
    public synchronized void downRecodeFileword(String fileEmcId, String fileName, String account) {
        try {
            //第一次请求获取 档案系统下载链接
            //档案系统文件ID
//            String fileEmcId = f.getFileEmcId();
            RecordsSystsemResquest recordsSystsemResquest = new RecordsSystsemResquest();
            recordsSystsemResquest.setFILE_ID(fileEmcId);
            //目前使用用户工号下载  同时使用一个用户下载会造成阻塞
            String reponseCon = HttpClientUtil.sendHttpPostJsonHasHeader(recordUrl, JSONObject.toJSONString(recordsSystsemResquest), account);
            //响应
            RecordsSystsemResponse recordsSystsemResponse = JSONObject.parseObject(reponseCon, RecordsSystsemResponse.class);
            String downUrl = recordsSystsemResponse.getRESPONSE();
            //第二次请求 获取文件到本地
            CloseableHttpClient client = HttpClients.createDefault();
            HttpGet httpget = new HttpGet(downUrl);
            CloseableHttpResponse response = client.execute(httpget);

            HttpEntity entity = response.getEntity();
            InputStream is = entity.getContent();
            String contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
            //把文件放置Minio桶(pdf文件夹)
            minIoUtil.putObject(minioProjectWord, fileName, is, contentType);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 下载pdf文件并上传到minio
     *
     * @param fileEmcId
     * @param fileName
     * @param account
     */
    public synchronized void downRecodeFilePdf(String fileEmcId, String fileName, String account) {
        try {
            //第一次请求获取 档案系统下载链接
            //档案系统文件ID
//            String fileEmcId = f.getFileEmcId();
            RecordsSystsemResquest recordsSystsemResquest = new RecordsSystsemResquest();
            recordsSystsemResquest.setFILE_ID(fileEmcId);
            //目前使用用户工号下载  同时使用一个用户下载会造成阻塞
            String reponseCon = HttpClientUtil.sendHttpPostJsonHasHeader(recordUrl, JSONObject.toJSONString(recordsSystsemResquest), account);
            //响应
            RecordsSystsemResponse recordsSystsemResponse = JSONObject.parseObject(reponseCon, RecordsSystsemResponse.class);
            String downUrl = recordsSystsemResponse.getRESPONSE();
            //第二次请求 获取文件到本地
            CloseableHttpClient client = HttpClients.createDefault();
            HttpGet httpget = new HttpGet(downUrl);
            CloseableHttpResponse response = client.execute(httpget);

            HttpEntity entity = response.getEntity();
            InputStream is = entity.getContent();
            String contentType = "application/pdf";
            //把文件放置Minio桶(pdf文件夹)
            minIoUtil.putObject(minioProjectPdf, fileName, is, contentType);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 下载文件到本地
     */
    public synchronized void nativeWord(String fileEmcId, String fileName, String account, String document) {
        try {
            //第一次请求获取 档案系统下载链接
            //档案系统文件ID
//            String fileEmcId = f.getFileEmcId();
            RecordsSystsemResquest recordsSystsemResquest = new RecordsSystsemResquest();
            recordsSystsemResquest.setFILE_ID(fileEmcId);
            //目前使用用户工号下载  同时使用一个用户下载会造成阻塞
            String reponseCon = HttpClientUtil.sendHttpPostJsonHasHeader(recordUrl, JSONObject.toJSONString(recordsSystsemResquest), account);
            //响应
            RecordsSystsemResponse recordsSystsemResponse = JSONObject.parseObject(reponseCon, RecordsSystsemResponse.class);
            String downUrl = recordsSystsemResponse.getRESPONSE();
            //第二次请求 获取文件到本地
            CloseableHttpClient client = HttpClients.createDefault();
            HttpGet httpget = new HttpGet(downUrl);
            CloseableHttpResponse response = client.execute(httpget);

            HttpEntity entity = response.getEntity();
            InputStream is = entity.getContent();
            Common.writeToLocal(document, is);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
